package com.gem.shop.service.impl;

import com.gem.shop.dao.CustomerDao;
import com.gem.shop.entity.Customer;
import com.gem.shop.service.CustomerService;
import com.gem.shop.util.BeanFactory;

/**
 * @author zhang
 * @date 2020/9/18 14:24
 */
public class CustomerServiceImpl implements CustomerService {

    CustomerDao customerDao = (CustomerDao) BeanFactory.getBean("customerDao");

    @Override
    public void register(String username, String password) {
        Customer customer = new Customer();
        customer.setUsername(username);
        customer.setPassword(password);
        customerDao.insertCustomer(customer);
    }

    @Override
    public void eidtCustomer(Customer customer) {
        customerDao.updateCustomer(customer);
    }

    @Override
    public Customer login(String username, String password) {
        return customerDao.selectCustomerByUsernameAndPassword(username,password);
    }

    @Override
    public Boolean checkUsername(String username) {
        Customer customer = customerDao.selectCustomerByName(username);
        if (customer == null){
            return true;
        }
        return false;
    }

    @Override
    public Customer findCustomerById(int id) {
        return customerDao.selectCustomerById(id);
    }
}
